#!/usr/bin/python3
# -*- coding: utf-8 -*-
import json
import re
import sys
import time
import tracemalloc

import demjson
sys.path.append("D:\workspace\mdd\spider-python\com")

from wushi.utils import dbutil
from wushi.utils.dbutil import connectDB
from wushi.utils.logutil import LogUtil
from wushi.vipspider.spider_config import CHANNEL, DB_HOST, DB_USER, DB_PASSWORD

"""
流程：brand详情（产品列表）->产品列表（翻页）->产品详情页面->解析产品详情数据->入库

通过mitmProxy解析rest接口获取产品详情数据；
爬取数据-支持多个颜色的商品；
直接写入DB，并通过DB进行幂等， key: productId + color    

#selenium.webdriver.chrome.options.Options
用于设置chrome浏览器，目前使用过的参数：
1、阻止chrome弹窗的出现：'profile.default_content_setting_values' :{'notifications' : 2}
2、不加载图片："profile.managed_default_content_settings.images":2
3、无头浏览器，--headless
"""


__author__ = 'Grant Wu'

import mitmproxy.http
from mitmproxy import ctx

logger = LogUtil("vipspider_mitmproxy_parser", __name__)


class Vip_Product_Spider_DataParser():
    vip_product_detail_url = 'https://mapi.vip.com/vips-mobile/rest/shopping/pc2/product/detail/v5'
    vip_product_detail_other_attr_url = 'https://mapi.vip.com/vips-mobile/rest/shopping/goods/pc2/vendorSkuList/v4'
    vip_product_detail_size_table_url = 'https://mapi.vip.com/vips-mobile/rest/shopping/pc/detail/size_table/v3'

    bandid_pattern = r'brandId\":\s*\"(\d+)\"'
    brand_store_sn_pattern = r'brandStoreSn\":\s*\"(\d+)\"'
    product_spu_id_pattern = r'prodSpuId\":\s*\"([\w-]+)\"'
    size_pattern = r'^sizeTableV3\((.+)\)$'

    def __init__(self):
        self.connect_db = connectDB('mmd_db', DB_HOST, DB_USER, DB_PASSWORD)
        # tracemalloc.start(20)
        # self.init_snapshot = tracemalloc.take_snapshot()
        # self.last_snap = self.init_snapshot

    def destroy(self):
        self.connect_db.close()

    def request(self, flow: mitmproxy.http.HTTPFlow):
        url = flow.request.url
        if Vip_Product_Spider_DataParser.vip_product_detail_url in url or Vip_Product_Spider_DataParser.vip_product_detail_other_attr_url in url:
            print('======>request: ', url)
        # headers = flow.request.headers
        # for (k,v) in headers:
        #     print('======>' + k +' = '+v)
        # ctx.log.info(demjson.encode(headers))

    def response(self, flow: mitmproxy.http.HTTPFlow):
        '''
        处理代理返回的response
        :param flow:
        :return:
        '''

        url = flow.request.url
        headers = flow.request.headers
        try:
            response = flow.response
            if not response:
                return
            response_header = response.headers
            content_type = response_header['Content-Type']
            if 'image' in content_type:
                print('这里返回的是图片')
            elif 'text/javascript' in content_type:
                if (response.status_code == 200):
                    self.print_request_response(flow)
                    # 解析产品详情数据
                    if Vip_Product_Spider_DataParser.vip_product_detail_url in url:
                        self.save_product_detail(response.text)
                        # self.print_memory()
                        # self.print_top_memory_traceback()
                    #  解析产品颜色、尺寸数据
                    if Vip_Product_Spider_DataParser.vip_product_detail_other_attr_url in url:
                        self.save_product_other_attr(response.text)
                    if Vip_Product_Spider_DataParser.vip_product_detail_size_table_url in url:
                        is_match = re.match(Vip_Product_Spider_DataParser.size_pattern, response.text)
                        if is_match:
                            data = is_match.group(1)
                            logger.info("======>size table data:{}",data)
                        self.save_product_size_table(data)
                        # self.print_memory()
                        # self.print_top_memory_traceback()
                # print('res_data-------------------->', response.text)
            # else:
                # print('格式非预期')
        except Exception as err:
            logger.error("拉取数据error， url: {} 错误描述:{}", url, err)
            print('======>error', err)
            # raise Exception

    def error(self, flow: mitmproxy.http.HTTPFlow):
        ctx.log.error(flow.error.msg)

    def print_memory(self):
        now_snap = tracemalloc.take_snapshot()
        last_compare = now_snap.compare_to(self.last_snap, 'lineno')
        print("[ last_compare Top 10 differences ]")
        for stat in last_compare[:10]:
            print(stat)
        init_compare = now_snap.compare_to(self.init_snapshot, 'lineno')
        print("[ init_compare Top 10 differences ]")
        for stat in init_compare[:10]:
            print(stat)
        self.last_snap = now_snap
    def print_top_memory_traceback(self):
        now_snap = tracemalloc.take_snapshot()
        top_stats = now_snap.statistics('traceback')

        # pick the biggest memory block
        stat = top_stats[0]
        print("======> %s memory blocks: %.1f KiB" % (stat.count, stat.size / 1024))
        for line in stat.traceback.format():
            print(line)

    def print_request_response(self, flow: mitmproxy.http.HTTPFlow):
        url = flow.request.url
        response = flow.response
        response_header = response.headers
        content_type = response_header['Content-Type']
        print('======>response start process url:', url)
        logger.info('======>response start process url:{}, ===>content_type{},====>code:{}', url, content_type, response.status_code)
        logger.info('======>response data:{}', response.text)


    def save_product_detail(self, json_data):
        """     对应：vip_product_detail_url
                解析产品基本信息
                :param old_brandIndex:
                :return:
                """
        print('======> save_product_detail start....')
        if not json_data:
            return None
        parent_data = demjson.decode(json_data, 'utf_8')
        if not parent_data["data"]:
            logger.warn("======>the data is null")
            return None
        try:
            dic = {}
            product = parent_data["data"]['product']
            # 在vip中brand_id时场次id，brand_store_sn才是供应商sn
            dic["brand_id"] = product['brandId']
            dic['brand_store_sn'] = product['brandStoreSn']
            dic['brand_name'] = product['brandStoreName']
            dic['brand_url'] = None

            dic["product_id"] = product['productId']
            # 关联 颜色、尺寸数据
            dic['product_spu_id'] = product['prodSpuId']
            dic["title"] = product['title']
            dic["sale_price"] = product['vipshopPrice']
            dic["sale_price_origin"] = product['marketPrice']
            dic["thumnail_img_link"] = product['smallImage']
            dic["details_link"] = 'https://detail.vip.com/detail-{}-{}.html'.format(str(dic["brand_id"]), str(dic["product_id"]))
            imgs = product['previewImages']
            # dic['imgs_link'] = [x['imageUrl'] for x in imgs]
            # 类别id
            dic['category_id'] = product['categoryId']
            properties = product['props']
            props = {}
            for x in properties:
                props[x['name']] = x['value']
            dic['properties'] = demjson.encode(props, encoding='utf-8')
            self.writedata_2_db(dic)
        except Exception as err:
            logger.error('======> save_product_detail error!!!! {},{}'.format(json_data), err)
        finally:
            dic.clear()
            props.clear()

    def save_product_other_attr(self, json_data):
        """     对应：vip_product_detail_url
            解析产品其他属性： SPU_ID,BrandId,
            :param json_data:
            :return:
        """
        if not json_data:
            return None
        # re.compile(bandid_pattern)
        try:
            # 返回的json格式不标准，采用截取str方式
            # parent_data = demjson.decode(json_data, 'utf_8')\
            # parent_data = json.loads(json_data,encoding='utf-8')
            # if not parent_data["data"]:
            #     logger.warn("======>the data is null")
            #     return None

            dic = {}

            brand_ids = re.findall(Vip_Product_Spider_DataParser.bandid_pattern, json_data)
            product_spu_ids = re.findall(Vip_Product_Spider_DataParser.product_spu_id_pattern, json_data)
            if not product_spu_ids:
                logger.warn('======>there is not product spuid data:{}'.format(json_data))
                return
            dic['product_spu_id'] = product_spu_ids[0]
            if not brand_ids:
                logger.warn('======>there is not brand ids data:{}'.format(json_data))
                return
            dic["brand_id"] = brand_ids[0]

            property_data = re.findall(r'saleProps\":(.*),\"showSingleColor', json_data)
            if not property_data:
                logger.warn('======>there is not properties data:{}'.format(json_data))
                return
            property_json = json.loads(property_data[0])
            # Step1 尺寸数据
            sizetable = property_json[0]
            size_datas={}
            for item in sizetable['values']:
                # 此处的sizeTableDetailId 对应尺码表ID
                size_datas[str(item['sizeTableDetailId'])] = item['name']
            dic['size'] = demjson.encode(size_datas, encoding='utf-8')

            # Step2 颜色数据
            colors = property_json[1]

            # colors['name']=='颜色'
            color_dic = {}
            for x in colors['values']:
                color_dic[x['name']] = [y['imageUrl'] for y in x['previewImages']]
            if(color_dic and len(color_dic)>0):
                dic['imgs_link'] = demjson.encode(color_dic, encoding='utf-8')
                dic['color'] = demjson.encode(color_dic.keys(),encoding='utf-8')
            else:
                dic['imgs_link'] = None
                dic['color'] = None
            self.write_product_other_attr_2_db(dic)
            logger.info('======>get the product success index:{}'.format(dic))
        except Exception as err:
            logger.error('======> save_product_other_attr error !!!! {},{}'.format(json_data),err)
        finally:
            dic.clear()
            size_datas.clear()
            color_dic.clear()

    def save_product_size_table(self, json_data):
        print('======> save_product_size_table start....')
        if not json_data:
            return None
        parent_data = demjson.decode(json_data, 'utf_8')
        if not parent_data["data"]:
            logger.warn("======>the data is null")
            return None
        try:
            result_data = []
            size_data = parent_data["data"]
            # 在vip中brand_id时场次id，brand_store_sn才是供应商sn
            details = size_data['details']
            if details is None or details.__len__()<=0:
                return
            for (key,detail) in details.items():
                dic = {}
                size_table_url = str(size_data['webPageUrl'])
                dic['size_table_url'] = size_table_url[0:1000] if size_table_url.__len__()>=1024 else size_table_url
                dic['platform'] = 'vip'
                dic['deleted'] = 0
                dic['size_dimension'] = detail['dimension']
                dic['size_table_id'] = detail['id']
                dic['size_name'] = detail['name']
                dic['display_order'] = detail['sizeDetailOrder']
                properties = detail['propertyValues']
                if properties is None or properties.__len__()<=0:
                    continue
                if isinstance(properties, dict):
                    for (k,v) in properties.items():
                        # 需要创建1个新的dict，否则执行同一个引用！！！
                        dic_temp = dic.copy()
                        dic_temp['attribute_key'] = k
                        dic_temp['attribute_value'] = v
                        result_data.append(dic_temp)
                elif isinstance(properties, list):
                    for prop in properties:
                        if prop.__contains__('='):
                            dic_temp = dic.copy()
                            kv = str.split(prop, '=')
                            dic_temp['attribute_key'] = kv[0]
                            dic_temp['attribute_value'] = kv[1]
                            result_data.append(dic_temp)
            self.write_size_table_data_2_db(result_data)
        except Exception as err:
            logger.error('======> save_product_size_table error!!!! {},{}'.format(json_data, err))
        finally:
            dic.clear()


    def parse_brand_id(self, product_list_url):
        """
        从产品详情url中解析褚brandid
        :param product_detail_url:  https://detail.vip.com/detail-1710613538-6919163397591892034.html
        :return:
        """
        pattern = r'^.+-(\d+?)-(\d+).html$'
        hasbrandid = re.match(pattern, product_list_url)
        if (hasbrandid):
            brandid = hasbrandid.groups(0)[0]
            return brandid
        return None

    def update_brand_status(self, brand_url, status):
        # connect_db = connectDB('mmd_db', '192.168.6.76', 'root', 'root')
        sql = "update mmd_db.bs_spider_brand_men set status = %d where product_list_url= '%s'" % (status, brand_url)
        dbutil.exeSql(sql, self.connect_db)
        # connect_db.close()

    def writedata_2_db(self, product):
        sql = """
                insert into mmd_db.bs_spider_product(product_id,title,channel,sale_price,sale_price_origin,thumnail_img_link,
                details_link,brand_id,brand_name,brand_store_sn,product_spu_id,imgs_link,color,properties,status,created_time,updated_time) 
                values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
                """
        args = (product['product_id'], product['title'], CHANNEL, product['sale_price'], product['sale_price_origin'],
                product['thumnail_img_link'], product['details_link'], product['brand_id'], product['brand_name'],
                product['brand_store_sn'], product['product_spu_id'], None, None, product['properties'], 0,
                time.time() * 1000, time.time() * 1000)
        data_id = dbutil.exeSqlWithArgs(sql, args, self.connect_db)

    def write_product_other_attr_2_db(self, product):
        sql = "update mmd_db.bs_spider_product set  imgs_link = '%s', color='%s',size = '%s' where brand_id = '%s' and product_spu_id='%s'"
        sql_filled = sql % (str(product['imgs_link'], encoding='utf-8'), str(product['color'],encoding='utf-8'), str(product['size'],encoding='utf-8'), product['brand_id'], product['product_spu_id'])
        retry_time=0
        while retry_time<3:
            logger.info('exe sql:{}'.format(sql_filled))
            result = dbutil.exeSql(sql_filled, self.connect_db)
            if not result or result == 0:
                logger.error('======>write data error:{}'.format(sql))
                time.sleep(1)
            else:
                break
            retry_time +=1

        logger.info('======>update attr for product:{}, result:{}'.format(sql_filled, result))

    def writedatas_2_db(self, prodcut_details):
        sql = """
        insert into mmd_db.bs_spider_product(product_id,title,channel,sale_price,sale_price_origin,thumnail_img_link,
        details_link,brand_id,brand_name,imgs_link,color,properties,status,created_time,updated_time) 
        values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
        """
        datas = []
        for product in prodcut_details:
            datas.append((product['product_id'], product['title'], CHANNEL, product['sale_price'],
                          product['sale_price_origin'], product['thumnail_img_link'], product['details_link'],
                          product['brand_id'], product['brand_name'], product['imgs_link'], product['color'],
                          product['properties'], 0, time.time() * 1000, time.time() * 1000))
        dbutil.exemanySql(datas, sql, self.connect_db)

    def write_size_table_data_2_db(self, size_table):
        sql = """
        insert into mmd_db.bs_spider_product_size_table(platform,size_table_id,size_name,size_dimension,attribute_key,attribute_value,
        display_order,size_table_url,deleted,created_time,updated_time) 
        values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
        """
        datas = []
        for product in size_table:
            datas.append((product['platform'], product['size_table_id'], product['size_name'],
                          product['size_dimension'], product['attribute_key'], product['attribute_value'],
                          int(product['display_order']), product['size_table_url'], 0, time.time() * 1000, time.time() * 1000))
        dbutil.exemanySql(datas, sql, self.connect_db)


    def product_detail_in_db(self, product_id, other_color_detail_url):
        sql = '''
          select * from mmd_db.bs_spider_product where product_id='{}' and details_link='{}'
        '''.format(product_id, other_color_detail_url)
        dbutil.exeSelectSql(sql, self.connect_db)


addons = [
    Vip_Product_Spider_DataParser()
]

if __name__ == "__main__":
    spider = Vip_Product_Spider_DataParser()
    product_data = """
    {"code":1,"data":{"batchBuy":"0","brandId":"1711231668","brandStoreSn":"10038806","categoryId":"390563","freightTipsMap":{"f1":{"tips":"新会员专享首单满38元免邮（限唯品自营商品，部分商品不可用）"}},"hideSizeTableDetail":"0","isExchange":"0","isXStore":"0","prepay_price_mapping":{},"prodSpuId":"SPU-0DA73C8880000487","product_price_range_mapping":{"6919450633789339412":{"blackListTips":"","bossChosen":"0","buyLimitMax":2,"buyLimitMin":1,"couponDisabled":0,"couponHide":"0","dutyfree":0,"favStatus":0,"floatingView":{"items":[{"icon":"https://h2.appsimg.com/b.appsimg.com/upload/mst/2020/11/09/189/d5fc2e7b82fab857ffc8cf28f96aa400.png","mainTitle":"9月3日上架"},{"icon":"https://h2.appsimg.com/b.appsimg.com/upload/mst/2020/11/06/128/8c65b414c38f51c44b04aa4cf84f75b5.png","mainTitle":"品牌好货","subTitle":"唯品会独家"}]},"freightTipsKey":"f1","goods_point_tips":"","historicalPriceChart":2,"invisible":0,"isHaiTao":0,"isMedicine":"0","kqMidRemindStatus":0,"longTitle":"nissen | 百褶裙女半身裙秋新款不规则口袋设计高腰显瘦格纹百搭时尚半截裙","markUpPurchase":1,"priceView":{"bgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/148/163064934265.png","comparePrice":{"price":"599","priceTips":"","style":"1"},"dkBgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/185/163064936855.png","finalPrice":{"price":"159","priceTips":"特卖价","subPriceTips":"抢"},"salePrice":{"saleDiscount":"2.7折","saleMarketPrice":"599","salePrice":"159","salePriceSuff":"","salePriceTag":"","salePriceTime":1631325600,"salePriceTimeType":2,"salePriceTips":"","salePriceType":"special"},"viewType":1},"promotionTipsKey":"6919450633789343508","smallImage":"/upload/merchandise/pdcvis/618663/2021/0810/111/473ed29d-e067-4e47-b1da-3c7f9d968c85.jpg","supportServices":[{"description":"本商品支持10天价保，订单签收成功后10天内唯品会的售卖价格发生降价可以申请价格保护。发起申请时，以用户申请时商品页面显示的商品购买价格，与用户订单中商品显示的支付金额进行比对；优惠券、立减金减免部分，不在比价范围内；如已价保订单发生退款，系统将自动从退款中扣除价保金额。点击查看更多。","exposed":1,"iconType":"1","jumpUrl":"https://mst.vip.com/9_23qAPyWSpMHIO6oy_V1A.php?wapid=mst_100018448&_src=mst&extra_banner=0&nova=1&nova_platform=1&mst_page_type=guide","title":"10天价保"}],"svipShowPriceText":""},"6919450633839691540":{"blackListTips":"","bossChosen":"0","buyLimitMax":2,"buyLimitMin":1,"couponDisabled":0,"couponHide":"0","dutyfree":0,"favStatus":0,"floatingView":{"items":[{"icon":"https://h2.appsimg.com/b.appsimg.com/upload/mst/2020/11/09/189/d5fc2e7b82fab857ffc8cf28f96aa400.png","mainTitle":"9月3日上架"},{"icon":"https://h2.appsimg.com/b.appsimg.com/upload/mst/2020/11/06/128/8c65b414c38f51c44b04aa4cf84f75b5.png","mainTitle":"品牌好货","subTitle":"唯品会独家"}]},"freightTipsKey":"f1","goods_point_tips":"","historicalPriceChart":2,"invisible":0,"isHaiTao":0,"isMedicine":"0","kqMidRemindStatus":0,"longTitle":"nissen | 百褶裙女半身裙秋新款不规则口袋设计高腰显瘦格纹百搭时尚半截裙","markUpPurchase":1,"priceView":{"bgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/148/163064934265.png","comparePrice":{"price":"599","priceTips":"","style":"1"},"dkBgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/185/163064936855.png","finalPrice":{"price":"159","priceTips":"特卖价","subPriceTips":"抢"},"salePrice":{"saleDiscount":"2.7折","saleMarketPrice":"599","salePrice":"159","salePriceSuff":"","salePriceTag":"","salePriceTime":1631325600,"salePriceTimeType":2,"salePriceTips":"","salePriceType":"special"},"viewType":1},"promotionTipsKey":"6919450633839695636","smallImage":"/upload/merchandise/pdcvis/618663/2021/0810/104/1fdb9fab-0ac3-49e6-bf38-5f6cb3e2344f.jpg","supportServices":[{"description":"本商品支持10天价保，订单签收成功后10天内唯品会的售卖价格发生降价可以申请价格保护。发起申请时，以用户申请时商品页面显示的商品购买价格，与用户订单中商品显示的支付金额进行比对；优惠券、立减金减免部分，不在比价范围内；如已价保订单发生退款，系统将自动从退款中扣除价保金额。点击查看更多。","exposed":1,"iconType":"1","jumpUrl":"https://mst.vip.com/9_23qAPyWSpMHIO6oy_V1A.php?wapid=mst_100018448&_src=mst&extra_banner=0&nova=1&nova_platform=1&mst_page_type=guide","title":"10天价保"}],"svipShowPriceText":""}},"promotionTipsMap":{"6919450633789347604":{},"6919450633906865940":{},"6919450633974007572":{},"6919450633890064148":{},"6919450633839687444":{},"6919450633789343508":{},"6919450633839695636":{},"6919450633906870036":{}},"rectangleType":"s","reservedVersion":"2","saleProps":[{"detail":0,"id":453,"name":"尺码","pid":"51666","showSizeTable":1,"type":"size","values":[{"description":"","detailImages":[],"id":3957,"itemDetailModules":[],"itemProperties":[],"name":"S","sizeTableDetailId":304595576,"sort":7,"vid":"83"},{"description":"","detailImages":[],"id":3958,"itemDetailModules":[],"itemProperties":[],"name":"M","sizeTableDetailId":304595579,"sort":8,"vid":"77"},{"description":"","detailImages":[],"id":3959,"itemDetailModules":[],"itemProperties":[],"name":"L","sizeTableDetailId":304595578,"sort":9,"vid":"76"},{"description":"","detailImages":[],"id":3960,"itemDetailModules":[],"itemProperties":[],"name":"XL","sizeTableDetailId":304595577,"sort":10,"vid":"2804"}]},{"detail":1,"id":134,"name":"颜色","pid":"48722","showSizeTable":0,"type":"color","values":[{"detailImages":[{"imageIndex":601,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/27/ef86a14e-4374-49ab-9b17-48cb9325d6f2.jpg"},{"imageIndex":602,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/163/23ab597f-8b7d-42b6-b8e6-296b51a1264d.jpg"},{"imageIndex":603,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/98/1ae0ef60-0eab-40b3-b848-82866f8f3a52.jpg"},{"imageIndex":604,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/101/fdb72c1a-c69b-4182-a371-63c8260bdd3e.jpg"},{"imageIndex":605,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/97/9e51ccf3-1ecf-4fcc-8f71-3c6d0c73d036.jpg"},{"imageIndex":606,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0813/16/80265c77-ee67-471f-a6ec-784a8a3b6aa8.jpg"},{"imageIndex":607,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/197/6186be88-bd15-427b-841d-6c4803538e13.jpg"},{"imageIndex":608,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/61/e2326f53-2c19-476d-af8e-0a470e0a577f.jpg"},{"imageIndex":609,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/38/6df61e39-c6fc-4bad-847b-b65c851bb7bb.jpg"},{"imageIndex":610,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/43/64566e50-2f28-4df3-ada6-8890df162d00.jpg"},{"imageIndex":611,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/31/1d4b70d4-110f-4f53-8315-983c30e738e2.jpg"},{"imageIndex":612,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/184/658c5653-41fc-4069-991c-26b909fa7289.jpg"},{"imageIndex":826,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/141/2bb6376d-862a-4b64-a540-fd200a167b78.jpg"},{"imageIndex":999999999,"imageUrl":"http://a.vpimg4.com/upload/category/2021/07/21/1/ad5a731d-9890-459f-9214-d618602a7fae.jpg"}],"icon":{"imageIndex":1,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/104/1fdb9fab-0ac3-49e6-bf38-5f6cb3e2344f.jpg"},"id":1657,"itemDetailModules":[{"name":"SUB_TITLE","value":"韩版时尚不对称百褶裙"}],"itemProperties":[],"name":"黑色","previewImages":[{"imageIndex":1,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/104/1fdb9fab-0ac3-49e6-bf38-5f6cb3e2344f.jpg"},{"imageIndex":2,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/195/6f933890-d0ff-487b-901b-259b07aafdd5.jpg"},{"imageIndex":3,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/21/f7f396db-7541-4f6f-9c1e-2435b503d7f1.jpg"},{"imageIndex":4,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/135/869ac6cd-162d-418d-aa10-cc9fa1861a40.jpg"},{"imageIndex":15,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/6/a3d675a3-ba7e-4550-9bf8-4b8009de9b59.jpg"}],"productId":"6919450633839691540","sizeTableDetailId":304595576,"sort":1,"vid":"1293761"},{"detailImages":[{"imageIndex":601,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/165/dad903dc-485d-4a6a-8103-5c7b2a045cd5.jpg"},{"imageIndex":602,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/48/b3a72909-9dcf-4c28-bb43-677708aed5a1.jpg"},{"imageIndex":603,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/28/f305cfd6-465f-4c43-bb97-4a26b64387c8.jpg"},{"imageIndex":604,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/176/915c90d7-e5dd-4266-8651-dc6608e20283.jpg"},{"imageIndex":605,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/57/fd821ee3-c0bd-402e-b151-7434263d22b3.jpg"},{"imageIndex":606,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0813/152/746602e6-28a0-4fb8-961c-a17cf323f775.jpg"},{"imageIndex":607,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/73/be49b204-0e35-4ae3-943f-ba7c2911c7f5.jpg"},{"imageIndex":608,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/173/19f6fdf1-8c4d-4d01-9220-ea0266190f62.jpg"},{"imageIndex":609,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/144/4d831e60-ee7d-4cd6-a30e-1b2e5d632a50.jpg"},{"imageIndex":610,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/49/e82b7376-9257-47a3-8734-1e7e2144fc26.jpg"},{"imageIndex":611,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/26/a60245ec-a6ac-4555-9ddc-29c950ef2923.jpg"},{"imageIndex":612,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/183/1a4fa02b-1043-4e41-976e-029dd98924cd.jpg"},{"imageIndex":826,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/198/74665532-218f-4c58-8a89-150c755080e0.jpg"},{"imageIndex":999999999,"imageUrl":"http://a.vpimg4.com/upload/category/2021/07/21/1/ad5a731d-9890-459f-9214-d618602a7fae.jpg"}],"icon":{"imageIndex":1,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/111/473ed29d-e067-4e47-b1da-3c7f9d968c85.jpg"},"id":1648,"itemDetailModules":[{"name":"SUB_TITLE","value":"韩版时尚不对称百褶裙"}],"itemProperties":[],"name":"棕色","previewImages":[{"imageIndex":1,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/111/473ed29d-e067-4e47-b1da-3c7f9d968c85.jpg"},{"imageIndex":2,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/2/5837ba04-fb62-4bf0-92b0-e90445c4555e.jpg"},{"imageIndex":3,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/187/367e4613-a7db-473d-91b6-93c0452145e1.jpg"},{"imageIndex":4,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/147/6399fdcd-c799-4503-8035-fdd768187f4b.jpg"},{"imageIndex":15,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/151/0ecb1cc9-4e8e-4f70-9983-8d94bc7abdfa.jpg"}],"productId":"6919450633789339412","sizeTableDetailId":304595578,"sort":7,"vid":"865341"}]}],"showSingleColor":"1","skus":{"48722:865341;51666:83":{"barcode":"N796375077802","couponDisabled":0,"couponHide":"0","creditRegisterUrl":"","creditTips":"","dutyfree":0,"freightTipsKey":"f1","goodsPoint":"","goodsPointTips":"","historicalPriceChart":2,"invisible":0,"mid":"6919450633789339412","msizeId":"6919450633890064148","prepay":"0","priceView":{"bgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/148/163064934265.png","comparePrice":{"price":"599","priceTips":"","style":"1"},"dkBgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/185/163064936855.png","finalPrice":{"price":"159","priceTips":"特卖价","subPriceTips":"抢"},"salePrice":{"saleDiscount":"2.7折","saleMarketPrice":"599","salePrice":"159","salePriceSuff":"","salePriceTag":"","salePriceTime":1631325600,"salePriceTimeType":2,"salePriceTips":"","salePriceType":"special"},"viewType":1},"promotionTipsKey":"6919450633890064148","reservedState":0,"reservedStateText":"","sellingSpeed":"20866","stock":11,"svipShowPriceText":"","type":0,"vSkuId":"671957804155514881"},"48722:1293761;51666:2804":{"barcode":"N796375074505","couponDisabled":0,"couponHide":"0","creditRegisterUrl":"","creditTips":"","dutyfree":0,"freightTipsKey":"f1","goodsPoint":"","goodsPointTips":"","historicalPriceChart":2,"invisible":0,"mid":"6919450633839691540","msizeId":"6919450633906865940","prepay":"0","priceView":{"bgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/148/163064934265.png","comparePrice":{"price":"599","priceTips":"","style":"1"},"dkBgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/185/163064936855.png","finalPrice":{"price":"159","priceTips":"特卖价","subPriceTips":"抢"},"salePrice":{"saleDiscount":"2.7折","saleMarketPrice":"599","salePrice":"159","salePriceSuff":"","salePriceTag":"","salePriceTime":1631325600,"salePriceTimeType":2,"salePriceTips":"","salePriceType":"special"},"viewType":1},"promotionTipsKey":"6919450633906865940","reservedState":0,"reservedStateText":"","sellingSpeed":"14694","stock":11,"svipShowPriceText":"","type":0,"vSkuId":"671957804155506797"},"48722:1293761;51666:76":{"barcode":"N796375074504","couponDisabled":0,"couponHide":"0","creditRegisterUrl":"","creditTips":"","dutyfree":0,"freightTipsKey":"f1","goodsPoint":"","goodsPointTips":"","historicalPriceChart":2,"invisible":0,"mid":"6919450633839691540","msizeId":"6919450633974007572","prepay":"0","priceView":{"bgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/148/163064934265.png","comparePrice":{"price":"599","priceTips":"","style":"1"},"dkBgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/185/163064936855.png","finalPrice":{"price":"159","priceTips":"特卖价","subPriceTips":"抢"},"salePrice":{"saleDiscount":"2.7折","saleMarketPrice":"599","salePrice":"159","salePriceSuff":"","salePriceTag":"","salePriceTime":1631325600,"salePriceTimeType":2,"salePriceTips":"","salePriceType":"special"},"viewType":1},"promotionTipsKey":"6919450633974007572","reservedState":0,"reservedStateText":"","sellingSpeed":"19984","stock":11,"svipShowPriceText":"","type":0,"vSkuId":"671957804155510791"},"48722:1293761;51666:77":{"barcode":"N796375074503","couponDisabled":0,"couponHide":"0","creditRegisterUrl":"","creditTips":"","dutyfree":0,"freightTipsKey":"f1","goodsPoint":"","goodsPointTips":"","historicalPriceChart":2,"invisible":0,"mid":"6919450633839691540","msizeId":"6919450633906870036","prepay":"0","priceView":{"bgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/148/163064934265.png","comparePrice":{"price":"599","priceTips":"","style":"1"},"dkBgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/185/163064936855.png","finalPrice":{"price":"159","priceTips":"特卖价","subPriceTips":"抢"},"salePrice":{"saleDiscount":"2.7折","saleMarketPrice":"599","salePrice":"159","salePriceSuff":"","salePriceTag":"","salePriceTime":1631325600,"salePriceTimeType":2,"salePriceTips":"","salePriceType":"special"},"viewType":1},"promotionTipsKey":"6919450633906870036","reservedState":0,"reservedStateText":"","sellingSpeed":"12049","stock":11,"svipShowPriceText":"","type":0,"vSkuId":"671957804155510822"},"48722:1293761;51666:83":{"barcode":"N796375074502","couponDisabled":0,"couponHide":"0","creditRegisterUrl":"","creditTips":"","dutyfree":0,"freightTipsKey":"f1","goodsPoint":"","goodsPointTips":"","historicalPriceChart":2,"invisible":0,"mid":"6919450633839691540","msizeId":"6919450633839695636","prepay":"0","priceView":{"bgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/148/163064934265.png","comparePrice":{"price":"599","priceTips":"","style":"1"},"dkBgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/185/163064936855.png","finalPrice":{"price":"159","priceTips":"特卖价","subPriceTips":"抢"},"salePrice":{"saleDiscount":"2.7折","saleMarketPrice":"599","salePrice":"159","salePriceSuff":"","salePriceTag":"","salePriceTime":1631325600,"salePriceTimeType":2,"salePriceTips":"","salePriceType":"special"},"viewType":1},"promotionTipsKey":"6919450633839695636","reservedState":0,"reservedStateText":"","sellingSpeed":"14988","stock":11,"svipShowPriceText":"","type":0,"vSkuId":"671957804155510831"},"48722:865341;51666:2804":{"barcode":"N796375077805","couponDisabled":0,"couponHide":"0","creditRegisterUrl":"","creditTips":"","dutyfree":0,"freightTipsKey":"f1","goodsPoint":"","goodsPointTips":"","historicalPriceChart":2,"invisible":0,"mid":"6919450633789339412","msizeId":"6919450633839687444","prepay":"0","priceView":{"bgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/148/163064934265.png","comparePrice":{"price":"599","priceTips":"","style":"1"},"dkBgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/185/163064936855.png","finalPrice":{"price":"159","priceTips":"特卖价","subPriceTips":"抢"},"salePrice":{"saleDiscount":"2.7折","saleMarketPrice":"599","salePrice":"159","salePriceSuff":"","salePriceTag":"","salePriceTime":1631325600,"salePriceTimeType":2,"salePriceTips":"","salePriceType":"special"},"viewType":1},"promotionTipsKey":"6919450633839687444","reservedState":0,"reservedStateText":"","sellingSpeed":"15282","stock":11,"svipShowPriceText":"","type":0,"vSkuId":"671957804155510834"},"48722:865341;51666:77":{"barcode":"N796375077803","couponDisabled":0,"couponHide":"0","creditRegisterUrl":"","creditTips":"","dutyfree":0,"freightTipsKey":"f1","goodsPoint":"","goodsPointTips":"","historicalPriceChart":2,"invisible":0,"mid":"6919450633789339412","msizeId":"6919450633789343508","prepay":"0","priceView":{"bgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/148/163064934265.png","comparePrice":{"price":"599","priceTips":"","style":"1"},"dkBgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/185/163064936855.png","finalPrice":{"price":"159","priceTips":"特卖价","subPriceTips":"抢"},"salePrice":{"saleDiscount":"2.7折","saleMarketPrice":"599","salePrice":"159","salePriceSuff":"","salePriceTag":"","salePriceTime":1631325600,"salePriceTimeType":2,"salePriceTips":"","salePriceType":"special"},"viewType":1},"promotionTipsKey":"6919450633789343508","reservedState":0,"reservedStateText":"","sellingSpeed":"13812","stock":11,"svipShowPriceText":"","type":0,"vSkuId":"671957804155514880"},"48722:865341;51666:76":{"barcode":"N796375077804","couponDisabled":0,"couponHide":"0","creditRegisterUrl":"","creditTips":"","dutyfree":0,"freightTipsKey":"f1","goodsPoint":"","goodsPointTips":"","historicalPriceChart":2,"invisible":0,"mid":"6919450633789339412","msizeId":"6919450633789347604","prepay":"0","priceView":{"bgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/148/163064934265.png","comparePrice":{"price":"599","priceTips":"","style":"1"},"dkBgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/185/163064936855.png","finalPrice":{"price":"159","priceTips":"特卖价","subPriceTips":"抢"},"salePrice":{"saleDiscount":"2.7折","saleMarketPrice":"599","salePrice":"159","salePriceSuff":"","salePriceTag":"","salePriceTime":1631325600,"salePriceTimeType":2,"salePriceTips":"","salePriceType":"special"},"viewType":1},"promotionTipsKey":"6919450633789347604","reservedState":0,"reservedStateText":"","sellingSpeed":"14988","stock":11,"svipShowPriceText":"","type":0,"vSkuId":"671957804155510838"}},"spuId":"671957804155502639"},"msg":"success","tid":"-6022363494406058145"}
""".replace('\r', '').replace('\n', '')
    # spider.save_product_detail(product_data)

    product_detail_attr = """
    {"code":1,"data":{"batchBuy":"0","brandId":"1711231668","brandStoreSn":"10038806","categoryId":"390563","freightTipsMap":{"f1":{"tips":"新会员专享首单满38元免邮（限唯品自营商品，部分商品不可用）"}},"hideSizeTableDetail":"0","isExchange":"0","isXStore":"0","prepay_price_mapping":{},"prodSpuId":"SPU-0DA73C8880000487","product_price_range_mapping":{"6919450633789339412":{"blackListTips":"","bossChosen":"0","buyLimitMax":2,"buyLimitMin":1,"couponDisabled":0,"couponHide":"0","dutyfree":0,"favStatus":0,"floatingView":{"items":[{"icon":"https://h2.appsimg.com/b.appsimg.com/upload/mst/2020/11/09/189/d5fc2e7b82fab857ffc8cf28f96aa400.png","mainTitle":"9月3日上架"},{"icon":"https://h2.appsimg.com/b.appsimg.com/upload/mst/2020/11/06/128/8c65b414c38f51c44b04aa4cf84f75b5.png","mainTitle":"品牌好货","subTitle":"唯品会独家"}]},"freightTipsKey":"f1","goods_point_tips":"","historicalPriceChart":2,"invisible":0,"isHaiTao":0,"isMedicine":"0","kqMidRemindStatus":0,"longTitle":"nissen | 百褶裙女半身裙秋新款不规则口袋设计高腰显瘦格纹百搭时尚半截裙","markUpPurchase":1,"priceView":{"bgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/148/163064934265.png","comparePrice":{"price":"599","priceTips":"","style":"1"},"dkBgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/185/163064936855.png","finalPrice":{"price":"159","priceTips":"特卖价","subPriceTips":"抢"},"salePrice":{"saleDiscount":"2.7折","saleMarketPrice":"599","salePrice":"159","salePriceSuff":"","salePriceTag":"","salePriceTime":1631325600,"salePriceTimeType":2,"salePriceTips":"","salePriceType":"special"},"viewType":1},"promotionTipsKey":"6919450633789343508","smallImage":"/upload/merchandise/pdcvis/618663/2021/0810/111/473ed29d-e067-4e47-b1da-3c7f9d968c85.jpg","supportServices":[{"description":"本商品支持10天价保，订单签收成功后10天内唯品会的售卖价格发生降价可以申请价格保护。发起申请时，以用户申请时商品页面显示的商品购买价格，与用户订单中商品显示的支付金额进行比对；优惠券、立减金减免部分，不在比价范围内；如已价保订单发生退款，系统将自动从退款中扣除价保金额。点击查看更多。","exposed":1,"iconType":"1","jumpUrl":"https://mst.vip.com/9_23qAPyWSpMHIO6oy_V1A.php?wapid=mst_100018448&_src=mst&extra_banner=0&nova=1&nova_platform=1&mst_page_type=guide","title":"10天价保"}],"svipShowPriceText":""},"6919450633839691540":{"blackListTips":"","bossChosen":"0","buyLimitMax":2,"buyLimitMin":1,"couponDisabled":0,"couponHide":"0","dutyfree":0,"favStatus":0,"floatingView":{"items":[{"icon":"https://h2.appsimg.com/b.appsimg.com/upload/mst/2020/11/09/189/d5fc2e7b82fab857ffc8cf28f96aa400.png","mainTitle":"9月3日上架"},{"icon":"https://h2.appsimg.com/b.appsimg.com/upload/mst/2020/11/06/128/8c65b414c38f51c44b04aa4cf84f75b5.png","mainTitle":"品牌好货","subTitle":"唯品会独家"}]},"freightTipsKey":"f1","goods_point_tips":"","historicalPriceChart":2,"invisible":0,"isHaiTao":0,"isMedicine":"0","kqMidRemindStatus":0,"longTitle":"nissen | 百褶裙女半身裙秋新款不规则口袋设计高腰显瘦格纹百搭时尚半截裙","markUpPurchase":1,"priceView":{"bgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/148/163064934265.png","comparePrice":{"price":"599","priceTips":"","style":"1"},"dkBgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/185/163064936855.png","finalPrice":{"price":"159","priceTips":"特卖价","subPriceTips":"抢"},"salePrice":{"saleDiscount":"2.7折","saleMarketPrice":"599","salePrice":"159","salePriceSuff":"","salePriceTag":"","salePriceTime":1631325600,"salePriceTimeType":2,"salePriceTips":"","salePriceType":"special"},"viewType":1},"promotionTipsKey":"6919450633839695636","smallImage":"/upload/merchandise/pdcvis/618663/2021/0810/104/1fdb9fab-0ac3-49e6-bf38-5f6cb3e2344f.jpg","supportServices":[{"description":"本商品支持10天价保，订单签收成功后10天内唯品会的售卖价格发生降价可以申请价格保护。发起申请时，以用户申请时商品页面显示的商品购买价格，与用户订单中商品显示的支付金额进行比对；优惠券、立减金减免部分，不在比价范围内；如已价保订单发生退款，系统将自动从退款中扣除价保金额。点击查看更多。","exposed":1,"iconType":"1","jumpUrl":"https://mst.vip.com/9_23qAPyWSpMHIO6oy_V1A.php?wapid=mst_100018448&_src=mst&extra_banner=0&nova=1&nova_platform=1&mst_page_type=guide","title":"10天价保"}],"svipShowPriceText":""}},"promotionTipsMap":{"6919450633789347604":{},"6919450633906865940":{},"6919450633974007572":{},"6919450633890064148":{},"6919450633839687444":{},"6919450633789343508":{},"6919450633839695636":{},"6919450633906870036":{}},"rectangleType":"s","reservedVersion":"2","saleProps":[{"detail":0,"id":453,"name":"尺码","pid":"51666","showSizeTable":1,"type":"size","values":[{"description":"","detailImages":[],"id":3957,"itemDetailModules":[],"itemProperties":[],"name":"S","sizeTableDetailId":304595576,"sort":7,"vid":"83"},{"description":"","detailImages":[],"id":3958,"itemDetailModules":[],"itemProperties":[],"name":"M","sizeTableDetailId":304595579,"sort":8,"vid":"77"},{"description":"","detailImages":[],"id":3959,"itemDetailModules":[],"itemProperties":[],"name":"L","sizeTableDetailId":304595578,"sort":9,"vid":"76"},{"description":"","detailImages":[],"id":3960,"itemDetailModules":[],"itemProperties":[],"name":"XL","sizeTableDetailId":304595577,"sort":10,"vid":"2804"}]},{"detail":1,"id":134,"name":"颜色","pid":"48722","showSizeTable":0,"type":"color","values":[{"detailImages":[{"imageIndex":601,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/27/ef86a14e-4374-49ab-9b17-48cb9325d6f2.jpg"},{"imageIndex":602,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/163/23ab597f-8b7d-42b6-b8e6-296b51a1264d.jpg"},{"imageIndex":603,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/98/1ae0ef60-0eab-40b3-b848-82866f8f3a52.jpg"},{"imageIndex":604,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/101/fdb72c1a-c69b-4182-a371-63c8260bdd3e.jpg"},{"imageIndex":605,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/97/9e51ccf3-1ecf-4fcc-8f71-3c6d0c73d036.jpg"},{"imageIndex":606,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0813/16/80265c77-ee67-471f-a6ec-784a8a3b6aa8.jpg"},{"imageIndex":607,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/197/6186be88-bd15-427b-841d-6c4803538e13.jpg"},{"imageIndex":608,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/61/e2326f53-2c19-476d-af8e-0a470e0a577f.jpg"},{"imageIndex":609,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/38/6df61e39-c6fc-4bad-847b-b65c851bb7bb.jpg"},{"imageIndex":610,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/43/64566e50-2f28-4df3-ada6-8890df162d00.jpg"},{"imageIndex":611,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/31/1d4b70d4-110f-4f53-8315-983c30e738e2.jpg"},{"imageIndex":612,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/184/658c5653-41fc-4069-991c-26b909fa7289.jpg"},{"imageIndex":826,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/141/2bb6376d-862a-4b64-a540-fd200a167b78.jpg"},{"imageIndex":999999999,"imageUrl":"http://a.vpimg4.com/upload/category/2021/07/21/1/ad5a731d-9890-459f-9214-d618602a7fae.jpg"}],"icon":{"imageIndex":1,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/104/1fdb9fab-0ac3-49e6-bf38-5f6cb3e2344f.jpg"},"id":1657,"itemDetailModules":[{"name":"SUB_TITLE","value":"韩版时尚不对称百褶裙"}],"itemProperties":[],"name":"黑色","previewImages":[{"imageIndex":1,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/104/1fdb9fab-0ac3-49e6-bf38-5f6cb3e2344f.jpg"},{"imageIndex":2,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/195/6f933890-d0ff-487b-901b-259b07aafdd5.jpg"},{"imageIndex":3,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/21/f7f396db-7541-4f6f-9c1e-2435b503d7f1.jpg"},{"imageIndex":4,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/135/869ac6cd-162d-418d-aa10-cc9fa1861a40.jpg"},{"imageIndex":15,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/6/a3d675a3-ba7e-4550-9bf8-4b8009de9b59.jpg"}],"productId":"6919450633839691540","sizeTableDetailId":304595576,"sort":1,"vid":"1293761"},{"detailImages":[{"imageIndex":601,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/165/dad903dc-485d-4a6a-8103-5c7b2a045cd5.jpg"},{"imageIndex":602,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/48/b3a72909-9dcf-4c28-bb43-677708aed5a1.jpg"},{"imageIndex":603,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/28/f305cfd6-465f-4c43-bb97-4a26b64387c8.jpg"},{"imageIndex":604,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/176/915c90d7-e5dd-4266-8651-dc6608e20283.jpg"},{"imageIndex":605,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/57/fd821ee3-c0bd-402e-b151-7434263d22b3.jpg"},{"imageIndex":606,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0813/152/746602e6-28a0-4fb8-961c-a17cf323f775.jpg"},{"imageIndex":607,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/73/be49b204-0e35-4ae3-943f-ba7c2911c7f5.jpg"},{"imageIndex":608,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/173/19f6fdf1-8c4d-4d01-9220-ea0266190f62.jpg"},{"imageIndex":609,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/144/4d831e60-ee7d-4cd6-a30e-1b2e5d632a50.jpg"},{"imageIndex":610,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/49/e82b7376-9257-47a3-8734-1e7e2144fc26.jpg"},{"imageIndex":611,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/26/a60245ec-a6ac-4555-9ddc-29c950ef2923.jpg"},{"imageIndex":612,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/183/1a4fa02b-1043-4e41-976e-029dd98924cd.jpg"},{"imageIndex":826,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/198/74665532-218f-4c58-8a89-150c755080e0.jpg"},{"imageIndex":999999999,"imageUrl":"http://a.vpimg4.com/upload/category/2021/07/21/1/ad5a731d-9890-459f-9214-d618602a7fae.jpg"}],"icon":{"imageIndex":1,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/111/473ed29d-e067-4e47-b1da-3c7f9d968c85.jpg"},"id":1648,"itemDetailModules":[{"name":"SUB_TITLE","value":"韩版时尚不对称百褶裙"}],"itemProperties":[],"name":"棕色","previewImages":[{"imageIndex":1,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/111/473ed29d-e067-4e47-b1da-3c7f9d968c85.jpg"},{"imageIndex":2,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/2/5837ba04-fb62-4bf0-92b0-e90445c4555e.jpg"},{"imageIndex":3,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/187/367e4613-a7db-473d-91b6-93c0452145e1.jpg"},{"imageIndex":4,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/147/6399fdcd-c799-4503-8035-fdd768187f4b.jpg"},{"imageIndex":15,"imageUrl":"/upload/merchandise/pdcvis/618663/2021/0810/151/0ecb1cc9-4e8e-4f70-9983-8d94bc7abdfa.jpg"}],"productId":"6919450633789339412","sizeTableDetailId":304595578,"sort":7,"vid":"865341"}]}],"showSingleColor":"1","skus":{"48722:865341;51666:83":{"barcode":"N796375077802","couponDisabled":0,"couponHide":"0","creditRegisterUrl":"","creditTips":"","dutyfree":0,"freightTipsKey":"f1","goodsPoint":"","goodsPointTips":"","historicalPriceChart":2,"invisible":0,"mid":"6919450633789339412","msizeId":"6919450633890064148","prepay":"0","priceView":{"bgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/148/163064934265.png","comparePrice":{"price":"599","priceTips":"","style":"1"},"dkBgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/185/163064936855.png","finalPrice":{"price":"159","priceTips":"特卖价","subPriceTips":"抢"},"salePrice":{"saleDiscount":"2.7折","saleMarketPrice":"599","salePrice":"159","salePriceSuff":"","salePriceTag":"","salePriceTime":1631325600,"salePriceTimeType":2,"salePriceTips":"","salePriceType":"special"},"viewType":1},"promotionTipsKey":"6919450633890064148","reservedState":0,"reservedStateText":"","sellingSpeed":"20866","stock":11,"svipShowPriceText":"","type":0,"vSkuId":"671957804155514881"},"48722:1293761;51666:2804":{"barcode":"N796375074505","couponDisabled":0,"couponHide":"0","creditRegisterUrl":"","creditTips":"","dutyfree":0,"freightTipsKey":"f1","goodsPoint":"","goodsPointTips":"","historicalPriceChart":2,"invisible":0,"mid":"6919450633839691540","msizeId":"6919450633906865940","prepay":"0","priceView":{"bgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/148/163064934265.png","comparePrice":{"price":"599","priceTips":"","style":"1"},"dkBgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/185/163064936855.png","finalPrice":{"price":"159","priceTips":"特卖价","subPriceTips":"抢"},"salePrice":{"saleDiscount":"2.7折","saleMarketPrice":"599","salePrice":"159","salePriceSuff":"","salePriceTag":"","salePriceTime":1631325600,"salePriceTimeType":2,"salePriceTips":"","salePriceType":"special"},"viewType":1},"promotionTipsKey":"6919450633906865940","reservedState":0,"reservedStateText":"","sellingSpeed":"14694","stock":11,"svipShowPriceText":"","type":0,"vSkuId":"671957804155506797"},"48722:1293761;51666:76":{"barcode":"N796375074504","couponDisabled":0,"couponHide":"0","creditRegisterUrl":"","creditTips":"","dutyfree":0,"freightTipsKey":"f1","goodsPoint":"","goodsPointTips":"","historicalPriceChart":2,"invisible":0,"mid":"6919450633839691540","msizeId":"6919450633974007572","prepay":"0","priceView":{"bgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/148/163064934265.png","comparePrice":{"price":"599","priceTips":"","style":"1"},"dkBgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/185/163064936855.png","finalPrice":{"price":"159","priceTips":"特卖价","subPriceTips":"抢"},"salePrice":{"saleDiscount":"2.7折","saleMarketPrice":"599","salePrice":"159","salePriceSuff":"","salePriceTag":"","salePriceTime":1631325600,"salePriceTimeType":2,"salePriceTips":"","salePriceType":"special"},"viewType":1},"promotionTipsKey":"6919450633974007572","reservedState":0,"reservedStateText":"","sellingSpeed":"19984","stock":11,"svipShowPriceText":"","type":0,"vSkuId":"671957804155510791"},"48722:1293761;51666:77":{"barcode":"N796375074503","couponDisabled":0,"couponHide":"0","creditRegisterUrl":"","creditTips":"","dutyfree":0,"freightTipsKey":"f1","goodsPoint":"","goodsPointTips":"","historicalPriceChart":2,"invisible":0,"mid":"6919450633839691540","msizeId":"6919450633906870036","prepay":"0","priceView":{"bgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/148/163064934265.png","comparePrice":{"price":"599","priceTips":"","style":"1"},"dkBgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/185/163064936855.png","finalPrice":{"price":"159","priceTips":"特卖价","subPriceTips":"抢"},"salePrice":{"saleDiscount":"2.7折","saleMarketPrice":"599","salePrice":"159","salePriceSuff":"","salePriceTag":"","salePriceTime":1631325600,"salePriceTimeType":2,"salePriceTips":"","salePriceType":"special"},"viewType":1},"promotionTipsKey":"6919450633906870036","reservedState":0,"reservedStateText":"","sellingSpeed":"12049","stock":11,"svipShowPriceText":"","type":0,"vSkuId":"671957804155510822"},"48722:1293761;51666:83":{"barcode":"N796375074502","couponDisabled":0,"couponHide":"0","creditRegisterUrl":"","creditTips":"","dutyfree":0,"freightTipsKey":"f1","goodsPoint":"","goodsPointTips":"","historicalPriceChart":2,"invisible":0,"mid":"6919450633839691540","msizeId":"6919450633839695636","prepay":"0","priceView":{"bgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/148/163064934265.png","comparePrice":{"price":"599","priceTips":"","style":"1"},"dkBgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/185/163064936855.png","finalPrice":{"price":"159","priceTips":"特卖价","subPriceTips":"抢"},"salePrice":{"saleDiscount":"2.7折","saleMarketPrice":"599","salePrice":"159","salePriceSuff":"","salePriceTag":"","salePriceTime":1631325600,"salePriceTimeType":2,"salePriceTips":"","salePriceType":"special"},"viewType":1},"promotionTipsKey":"6919450633839695636","reservedState":0,"reservedStateText":"","sellingSpeed":"14988","stock":11,"svipShowPriceText":"","type":0,"vSkuId":"671957804155510831"},"48722:865341;51666:2804":{"barcode":"N796375077805","couponDisabled":0,"couponHide":"0","creditRegisterUrl":"","creditTips":"","dutyfree":0,"freightTipsKey":"f1","goodsPoint":"","goodsPointTips":"","historicalPriceChart":2,"invisible":0,"mid":"6919450633789339412","msizeId":"6919450633839687444","prepay":"0","priceView":{"bgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/148/163064934265.png","comparePrice":{"price":"599","priceTips":"","style":"1"},"dkBgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/185/163064936855.png","finalPrice":{"price":"159","priceTips":"特卖价","subPriceTips":"抢"},"salePrice":{"saleDiscount":"2.7折","saleMarketPrice":"599","salePrice":"159","salePriceSuff":"","salePriceTag":"","salePriceTime":1631325600,"salePriceTimeType":2,"salePriceTips":"","salePriceType":"special"},"viewType":1},"promotionTipsKey":"6919450633839687444","reservedState":0,"reservedStateText":"","sellingSpeed":"15282","stock":11,"svipShowPriceText":"","type":0,"vSkuId":"671957804155510834"},"48722:865341;51666:77":{"barcode":"N796375077803","couponDisabled":0,"couponHide":"0","creditRegisterUrl":"","creditTips":"","dutyfree":0,"freightTipsKey":"f1","goodsPoint":"","goodsPointTips":"","historicalPriceChart":2,"invisible":0,"mid":"6919450633789339412","msizeId":"6919450633789343508","prepay":"0","priceView":{"bgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/148/163064934265.png","comparePrice":{"price":"599","priceTips":"","style":"1"},"dkBgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/185/163064936855.png","finalPrice":{"price":"159","priceTips":"特卖价","subPriceTips":"抢"},"salePrice":{"saleDiscount":"2.7折","saleMarketPrice":"599","salePrice":"159","salePriceSuff":"","salePriceTag":"","salePriceTime":1631325600,"salePriceTimeType":2,"salePriceTips":"","salePriceType":"special"},"viewType":1},"promotionTipsKey":"6919450633789343508","reservedState":0,"reservedStateText":"","sellingSpeed":"13812","stock":11,"svipShowPriceText":"","type":0,"vSkuId":"671957804155514880"},"48722:865341;51666:76":{"barcode":"N796375077804","couponDisabled":0,"couponHide":"0","creditRegisterUrl":"","creditTips":"","dutyfree":0,"freightTipsKey":"f1","goodsPoint":"","goodsPointTips":"","historicalPriceChart":2,"invisible":0,"mid":"6919450633789339412","msizeId":"6919450633789347604","prepay":"0","priceView":{"bgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/148/163064934265.png","comparePrice":{"price":"599","priceTips":"","style":"1"},"dkBgImg":"http://b.appsimg.com/upload/mcp/2021/09/03/185/163064936855.png","finalPrice":{"price":"159","priceTips":"特卖价","subPriceTips":"抢"},"salePrice":{"saleDiscount":"2.7折","saleMarketPrice":"599","salePrice":"159","salePriceSuff":"","salePriceTag":"","salePriceTime":1631325600,"salePriceTimeType":2,"salePriceTips":"","salePriceType":"special"},"viewType":1},"promotionTipsKey":"6919450633789347604","reservedState":0,"reservedStateText":"","sellingSpeed":"14988","stock":11,"svipShowPriceText":"","type":0,"vSkuId":"671957804155510838"}},"spuId":"671957804155502639","userContext":"{\"t\":1630976568,\"c\":4,\"u\":\"MA==\",\"v\":\"23\",\"mab\":{\"4387\":{\"r\":\"A\",\"v\":[\"if_show_tips:2\"]},\"4453\":{\"r\":\"X\",\"v\":[]},\"7940\":{\"r\":\"B\",\"v\":[]},\"4740\":{\"r\":\"A\",\"v\":[]},\"4773\":{\"r\":\"B\",\"v\":[]},\"2032\":{\"r\":\"A\",\"v\":[]},\"4280\":{\"r\":\"B\",\"v\":[\"isAutoGetCoupon:1\",\"isAutoGetCouponForPreheat:1\"]},\"4566\":{\"r\":\"B\",\"v\":[]},\"3875\":{\"r\":\"B\",\"v\":[\"brand_product_video:1\",\"is_realtime:1\",\"mixbrand_abt:3940_4317_3971_4411\",\"realtime_expose:1\",\"vre_attach_product:1\",\"is_limitprice:1\",\"brand_image:0\"]},\"4843\":{\"r\":\"A\",\"v\":[]},\"4447\":{\"r\":\"B\",\"v\":[]},\"4415\":{\"r\":\"B\",\"v\":[]},\"4526\":{\"r\":\"A\",\"v\":[]},\"4559\":{\"r\":\"B\",\"v\":[]},\"1913\":{\"r\":\"B\",\"v\":[]},\"4307\":{\"r\":\"B\",\"v\":[]},\"7915\":{\"r\":\"B\",\"v\":[]}},\"uab\":{}}"},"msg":"success","tid":"-6022363494406058145"}
""".replace('\r', '').replace('\n', '')

    # spider.save_product_other_attr(product_detail_attr)

    # product_size_table="""
    # {"code":1,"msg":"success","tid":"-6022363746979741518","data":{"id":"62091647","tips":"尺码均为手工测量有误差1一3厘米","details":{"304595576":{"id":"304595576","name":"S","propertyValues":{"裙长(cm)":"42","腰围(cm)":"65","臀围(cm)":"92","号型":"155/80A"},"dimension":"号型,腰围(cm),臀围(cm),裙长(cm)","sizeDetailOrder":1},"304595579":{"id":"304595579","name":"M","propertyValues":{"裙长(cm)":"43","腰围(cm)":"69","臀围(cm)":"96","号型":"160/84A"},"dimension":"号型,腰围(cm),臀围(cm),裙长(cm)","sizeDetailOrder":2},"304595578":{"id":"304595578","name":"L","propertyValues":{"裙长(cm)":"44","腰围(cm)":"73","臀围(cm)":"100","号型":"165/88A"},"dimension":"号型,腰围(cm),臀围(cm),裙长(cm)","sizeDetailOrder":3},"304595577":{"id":"304595577","name":"XL","propertyValues":{"裙长(cm)":"45","腰围(cm)":"77","臀围(cm)":"104","号型":"170/92A"},"dimension":"号型,腰围(cm),臀围(cm),裙长(cm)","sizeDetailOrder":4}},"sizeMeasurePic":"http://a.vpimg4.com/upload/category/2016/07/01/36/07daac4e-0df0-4797-ba22-5f67ff5ea23d.jpg","webPageUrl":"https://mst.vip.com/C9xzUpE-hXrRPYrZhNqb7w.php?wapid=mst_100013425&_src=mst&extra_banner=115013425&nova=1&nova_platform=1&mst_page_type=guide&product_id=6919450633839691540&spu_id=671957804155502639&brand_id=1711231668&size_table_id=62091647&roleId=&showFeelSize=C"}}
    # """
    product_size_table="""
    sizeTableV3({"code":1,"msg":"success","tid":"-6022363746979741518","data":{"id":"62091647","tips":"尺码均为手工测量有误差1一3厘米","details":{"304595576":{"id":"304595576","name":"S","propertyValues":{"裙长(cm)":"42","腰围(cm)":"65","臀围(cm)":"92","号型":"155/80A"},"dimension":"号型,腰围(cm),臀围(cm),裙长(cm)","sizeDetailOrder":1},"304595579":{"id":"304595579","name":"M","propertyValues":{"裙长(cm)":"43","腰围(cm)":"69","臀围(cm)":"96","号型":"160/84A"},"dimension":"号型,腰围(cm),臀围(cm),裙长(cm)","sizeDetailOrder":2},"304595578":{"id":"304595578","name":"L","propertyValues":{"裙长(cm)":"44","腰围(cm)":"73","臀围(cm)":"100","号型":"165/88A"},"dimension":"号型,腰围(cm),臀围(cm),裙长(cm)","sizeDetailOrder":3},"304595577":{"id":"304595577","name":"XL","propertyValues":{"裙长(cm)":"45","腰围(cm)":"77","臀围(cm)":"104","号型":"170/92A"},"dimension":"号型,腰围(cm),臀围(cm),裙长(cm)","sizeDetailOrder":4}},"sizeMeasurePic":"http://a.vpimg4.com/upload/category/2016/07/01/36/07daac4e-0df0-4797-ba22-5f67ff5ea23d.jpg","webPageUrl":"https://mst.vip.com/C9xzUpE-hXrRPYrZhNqb7w.php?wapid=mst_100013425&_src=mst&extra_banner=115013425&nova=1&nova_platform=1&mst_page_type=guide&product_id=6919450633839691540&spu_id=671957804155502639&brand_id=1711231668&size_table_id=62091647&roleId=&showFeelSize=C"}})
    """.strip("\n").strip(" ")
    pattern = r'^sizeTableV3\((.+)\)$'
    is_match = re.match(pattern,product_size_table)
    if is_match:
        data = is_match.group(1)
    spider.save_product_size_table(data)

    spider.destroy()
